package com.company.zoj;

import javafx.scene.layout.Priority;

import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * Created by v on 17-6-8.
 */
public class ZojTest1610 {
    private static class Node{
        int begin;
        int end;
        Node left;
        Node right;

        int status;

        public Node(int begin,int end){
            this.begin=begin;
            this.end=end;
            this.status=-1;
        }
    }

    private static Node root;

    private static int size=8000;

    private static int current;

    private static Map<Integer,Integer> map;

    private static void init(){
        current=-1;
        map=new TreeMap<>();
        root=build(0,size);
    }

    private static void insert(int begin,int end,int status,Node node){
        if(node.status==status){
            return;
        }

        if(node.begin==begin&&node.end==end){
            node.status=status;
            return;
        }

        if(node.status!=-1){
            node.left.status=node.status;
            node.right.status=node.status;
            node.status=-1;
        }

        int mid=(node.begin+node.end)/2;

        if(begin>=mid){
            insert(begin,end,status,node.right);
        }else if(end<=mid){
            insert(begin,end,status,node.left);
        }else {
            insert(begin,mid,status,node.left);
            insert(mid,end,status,node.right);
        }
    }

    private static Node build(int begin,int end){
        Node node=new Node(begin,end);
        if(end-begin<2){
            return node;
        }

        int mid=(begin+end)/2;
        node.left=build(begin,mid);
        node.right=build(mid,end);

        return node;
    }

    private static void solve(Node node){

        if(node.status==-1){
            if(node.left!=null){
                solve(node.left);
            }else {
                current=-1;
            }
            if(node.right!=null){
                solve(node.right);
            }else {
                current=-1;
            }
        }

        if(current==node.status||(node.status==-1&&node.left!=null)){
            return;
        }else {
            current=node.status;
            if(current!=-1){
                if(map.containsKey(current)){
                    map.put(current,map.get(current)+1);
                }else {
                    map.put(current,1);
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);

        try {
            while (true){
                init();
                int n=input.nextInt();

                for(int i=0;i<n;i++){
                    int begin=input.nextInt();
                    int end=input.nextInt();
                    int status=input.nextInt();

                    insert(begin,end,status,root);
                }
                solve(root);

                for(Map.Entry<Integer,Integer> entry:map.entrySet()){
                    System.out.println(entry.getKey()+" "+entry.getValue());
                }
                System.out.println();
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
